package com.relax;

import java.util.concurrent.locks.LockSupport;

public class ThreadDemo {
    static int sum = 0;

    public static void main(String[] args) {
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("thread1 start");
                //线程1会阻塞
                LockSupport.park();
                System.out.println("thread1 end");
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {


                System.out.println("thread2 start");
                //给线程1授权
                LockSupport.unpark(thread1);
                System.out.println("thread2 end");
            }
        });
        thread1.start();
        thread2.start();
    }

    private static void calcute() {
        for (int i = 0; i < 100000; i++) {
            sum ++;
            System.out.println(sum);
        }

    }
}
